package com.cheng.controller;

import com.cheng.common.exception.CommonException;
import com.cheng.common.results.DataRslt;
import com.cheng.data.entity.CompanyBaseInfoEntity;
import com.cheng.data.vo.CompanyBaseInfoVO;
import com.cheng.operation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: ChengJW
 * @date: 2021/9/19 18:24
 * @version: 1.0
 * @description: 档案登记页面的请求处理类
 */
@Controller
public class ArchivesAcceptController extends BaseController{

    private final static Logger logger = LoggerFactory.getLogger(ArchivesAcceptController.class);

    @Autowired
    private CompanyBaseInfoOperation companyBaseInfoOperation;

    @Autowired
    private EntpTypeInfOperation entpTypeInfOperation;

    @Autowired
    private ArchiveTypeInfOperation archiveTypeInfOperation;

    @Autowired
    private GvmtTypeInfOperation gvmtTypeInfOperation;

    @Autowired
    private TradeTypeInfOperation tradeTypeInfOperation;

    @Autowired
    private AcceptInfoOperation acceptInfoOperation;


    /**
    * @author: ChengJW
    * @params: []
    * @return: java.lang.String
    * @date: 2021/9/19
    * @description: 跳转至档案登记页面
    */
    @RequestMapping("/business/archivesAccept")
    public String archivesAccept(){
        return "archivesAccept";
    }

    /**
    * @author: ChengJW
    * @params: [vo, request]
    * @return: com.cheng.common.utils.ResultData
    * @date: 2021/9/20
    * @description: 档案登记查询
    */
    @RequestMapping("/business/archivesAccept/selectCompanyBaseInfo")
    @ResponseBody
    public DataRslt selectCompanyBaseInfo(CompanyBaseInfoVO vo, HttpServletRequest request) throws CommonException {

        CompanyBaseInfoEntity companyBaseInfoEntity = new CompanyBaseInfoEntity();
        BeanUtils.copyProperties(vo,companyBaseInfoEntity);
        //是否登记 0 未登记；1 已登记
        companyBaseInfoEntity.setCyRegistCd("0");
        //所属单位代码
        companyBaseInfoEntity.setCyMgeCode(getUrCode());
        CompanyBaseInfoEntity entity  = companyBaseInfoOperation.queryCompanyBaseInfo(companyBaseInfoEntity);
        if (null != entity) {
            CompanyBaseInfoVO companyBaseInfoVO = new CompanyBaseInfoVO();
            BeanUtils.copyProperties(entity,companyBaseInfoVO);
            //企业类型
            companyBaseInfoVO.setCyType(entpTypeInfOperation.queryEntpTypeInfByCode(entity.getCyType()));
            //档案类型
            companyBaseInfoVO.setCyArchTpye(archiveTypeInfOperation.queryArchiveTypeInfNmByCode(entity.getCyArchTpye()));
            //管辖机关类型
            companyBaseInfoVO.setCyRegistDeptNm(gvmtTypeInfOperation.queryGvmtTypeInfNmByCode(entity.getCyRegistDeptNm()));
            companyBaseInfoVO.setCyMgeNm(gvmtTypeInfOperation.queryGvmtTypeInfNmByCode(entity.getCyMgeNm()));
            //行业类型
            companyBaseInfoVO.setCyTradeTpye(tradeTypeInfOperation.queryTradeTypeInfNmByCode(entity.getCyTradeTpye()));
            return success(companyBaseInfoVO);
        }
        return failure();
    }

    /**
     * @author: ChengJW
     * @params: [atAcptId]
     * @return: com.cheng.common.utils.ResultData
     * @date: 2021/9/20
     * @description: 登记查询到的企业信息
     */
    @RequestMapping("/business/archivesAccept/insetCompanyInfoIntoTable")
    @ResponseBody
    public DataRslt insetCompanyInfoIntoTable(String atAcptId) throws CommonException{
        acceptInfoOperation.insertAcceptInfo(atAcptId);
        return success();
    }
}
